<?php
include('/classes/SQL_class.php');
include('/classes/Site_class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web semantique</title>
<style type="text/css">
table{
	border-collapse:collapse;
	margin:20px 0 0 0;
}
td, th{
	border:1px solid #000;
}
th{
	font-weight:bold;
	color:#FFF;
	background-color:#09F;
}
td.chemin{
	width:400px;
}
</style>
</head>

<body>
<p><a href="/websem/indexation.php" title="Indexation">Indexation</a><br/>
<a href="/websem/ponderation.php" title="Pond&eacute;ration">Pond&eacute;ration</a></p>
<?php
$rappel = '';
$result = array();
$requete ='';
$tabMot = array();
$search = array();
$replace = array();
if(isset($_POST['requete'])){
	$rappel = $_POST['requete'];
	$tabMot = Site::filtrerMot($rappel);
	if(count($tabMot)){
		$requete = 'SELECT p.*, g.chemin, g.texte, d.name FROM ponderation p, paragraphe g, document d, mot m WHERE (';
		foreach($tabMot as $mot => $compteur){
			$requete .= 'm.libelle = \''.$mot.'\' OR ';
			
		}
		$requete = substr($requete, 0, -3).')';
		$requete .= ' AND p.id_mot = m.id AND p.id_paragraphe = g.id AND g.id_document = d.id ORDER BY poids DESC;';
		
	}
	$conn = SQL::getInstance();
	$result = $conn->query($requete);
}
?>
<form action="index.php" method="post" >
	<input type="text" name="recherche" value="<?php echo $rappel; ?>" />
    <input type="submit" name="filtrer" id="filtrer" value="Filtrer" />
</form>
<p>
<?php
if(isset($_POST['recherche'])){
	echo Site::filtrerStopFile($_POST['recherche']);
}
?>
</p>
<form action="" method="post" >
	<input type="text" name="requete" value="<?php echo $rappel; ?>" />
    <input type="submit" name="rechercher" id="rechercher" value="Rechercher" />
</form>
<table cellspacing="0">
	<tr>
    <th>id_paragraphe</th>
    <th>chemin</th>
    <th>paragraphe</th>
    </tr>
<?php
foreach($result as $ligne){?>
	<tr>
    <td><?php echo $ligne['id_paragraphe'];?></td>
    <td class="chemin"><?php echo $ligne['chemin'];?></td>
    <td><?php echo $ligne['texte'];?></td>
    </tr><?php
}
?>
</table>
</body>
</html>
<?php
/*
SELECT p.*, g.chemin, g.texte, d.name FROM ponderation p, paragraphe g, document d WHERE p.id_mot = 5 AND p.id_paragraphe = g.id AND g.id_document = d.id ORDER BY poids DESC;
*/
?>